﻿//-----------------------------------------------------------------
//
// @(#)$Id: OrderFromDetails.aspx.cs,v 1.0 2013/12/13 17:20:18 lichunhua Exp $
// @(#)$Author: lichunhua  $
// @(#)$Date: 2013/12/13 17:20:18 $
// @(#)$Description:
//
//
//
//                 All Rights Reserved.
//-----------------------------------------------------------------
using System;
using System.Data;
using ebay.Dal.CenterDB_OrderTableAdapters;

public partial class UI_Bas_OrderFromDetails : System.Web.UI.Page
{
    static string act = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {           
            act = Request.QueryString["act"];
            if (!string.IsNullOrEmpty(act))
            {
                switch (act)
                {
                    case "I":
                        break;
                    case "U":
                        {
                            this.txtId.Attributes["readonly"] = "readonly";
                            int id = int.Parse(Request.QueryString["id"]);
                            T_OrderSourceTableAdapter ebayAdapter = new T_OrderSourceTableAdapter();
                            DataTable dt = ebayAdapter.GetDataById(id);
                            DataRow r = dt.Rows[0];
                            txtId.Value = r["Id"].ToString();
                            txtOrderFromName.Value = r["OrderFromName"].ToString();
                        }
                        break;
                }
            }

        }
    }
    
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)
        {
            WebUtility.ShowMsg("登陆超时,请重新登陆", this);
            return;
        }
        if (!string.IsNullOrEmpty(act))
        {
            switch (act)
            {
                case "I":
                    {
                      T_OrderSourceTableAdapter ebayAdapter = new T_OrderSourceTableAdapter();
                      int flag = (int)ebayAdapter.IsExists(int.Parse(txtId.Value));
                      if (flag == 0)
                      {
                          int val = ebayAdapter.Insert(
                                   int.Parse(txtId.Value),
                                   txtOrderFromName.Value
                                   );
                          if (val > 0)
                          {
                              Response.Write("<script>alert('添加成功!');window.location.href='OrderFrom.aspx'</script>");
                          }
                      }
                      else
                      {
                          Response.Write("<script>alert('编号已经存在!..');</script>");
                      }
                    }
                    break;
                case "U":
                    {
                        T_OrderSourceTableAdapter ebayAdapter = new T_OrderSourceTableAdapter();
                        int val = ebayAdapter.Update(
                            txtOrderFromName.Value,
                            int.Parse(txtId.Value));                                  
                        if (val > 0)
                        {
                            Response.Write("<script>alert('修改成功!');window.location.href='OrderFrom.aspx'</script>");
                        }
                    }
                    break;
                default:
                    break;
            }
        }
    }
}

